<template>
    <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="30%"
    >
        <el-form  label-width="80px" :model="formdata">
            <el-form-item label="头像">
                <el-avatar shape="square"
                        :size="50"
                        fit="contain"
                        :src="formdata.headimgurl">
                </el-avatar>
            </el-form-item>
            <el-form-item label="姓名">
                <el-input v-model="formdata.name"></el-input>
            </el-form-item>
            <el-form-item label="班级">
                <el-input v-model="formdata.class"></el-input>
            </el-form-item>
            <el-form-item label="项目地址">
                <el-input v-model="formdata.productUrl"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="editStu" :loading="loading">确 定</el-button>
            <el-button @click="dialogVisible = false">取 消</el-button>
        </span>
    </el-dialog>
</template>
<script>
    import {updateStu} from "../api/index"
    export default{
        data () {
            return {
                dialogVisible:false,
                loading:false,
                sId:"",
                formdata:{
                    headimgurl:"",
                    name:"",
                    class:"",
                    productUrl:""
                }
            }
        },
        methods: {
            editStu(){
                const info={
                    sId:this.sId,
                    token:localStorage.getItem("stu-login-token"),
                    name:this.formdata.name,
                    class:this.formdata.class,
                    productUrl:this.formdata.productUrl
                }
                updateStu(info)
                .then(res=>{
                    this.loading=true
                    if(res.data.state){
                        this.$bus.$emit("editupdate")
                        Object.keys(this.formdata).forEach(key => this.formdata[key] = '')
                        this.dialogVisible=false
                        setTimeout(()=>{
                            this.loading=false
                        },800)
                    }
                })
            }
        },
        mounted () {
            this.$bus.$on("showdialog",(res)=>{
                console.log(res)
                this.sId=res.sId
                this.dialogVisible=true
                this.formdata=Object.assign({},res)
            })
        }
    }
</script>